package cn.com.mall.ware.service.impl;

import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.com.mall.common.utils.PageUtils;
import cn.com.mall.common.utils.Query;

import cn.com.mall.ware.dao.WmsPurchaseDetailDao;
import cn.com.mall.ware.entity.WmsPurchaseDetailEntity;
import cn.com.mall.ware.service.WmsPurchaseDetailService;
import org.springframework.util.StringUtils;


@Service("wmsPurchaseDetailService")
public class WmsPurchaseDetailServiceImpl extends ServiceImpl<WmsPurchaseDetailDao, WmsPurchaseDetailEntity> implements WmsPurchaseDetailService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<WmsPurchaseDetailEntity> wrapper = new QueryWrapper<>();

        String status=(String)params.get("status");
        String wareId=(String)params.get("wareId");
        String key=(String)params.get("key");
        if(!StringUtils.isEmpty(status)){
            wrapper.eq("status",status);
        }

        if(!StringUtils.isEmpty(wareId)){
            wrapper.eq("ware_id",wareId);
        }
        if(!StringUtils.isEmpty(key)){
            wrapper.and(item->{
                item.eq("id",key).or().like("purchase_id",key).or().like("sku_id",key);
            });
        }

        IPage<WmsPurchaseDetailEntity> page = this.page(
                new Query<WmsPurchaseDetailEntity>().getPage(params),wrapper

        );

        return new PageUtils(page);
    }

}